/* @(#)FseDocumentSectionParagraphEditorContentView.java
** 
** Copyright (C) 2012 by Steven D. Stamps
**
**             Trademarks & Copyrights
** Flywheel Management Science(TM), Flywheel Management Model(TM),
** Flywheel Story Editor(TM) and FlywheelMS(TM) are exclusive trademarks
** of Steven D. Stamps and may only be used freely for the purpose of
** identifying the unforked version of this software.  Subsequent forks
** may not use these trademarks.  All other rights are reserved.
**
** DecKanGL (Decorated Kanban Glyph Language) and TribKn (Tribal Knowledge)
** are also exclusive trademarks of Steven D. Stamps.  These may be used
** freely within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** gConGUI (game Controller Graphical User Interface) is an exclusive
** trademark of Steven D. Stamps.  This trademark may be used freely
** within the unforked FlywheelMS application and documentation.
** All other rights are reserved.
**
** Trademark information is available at
** <http://www.flywheelms.com/trademarks>
**
** Flywheel Management Science(TM) is a copyrighted body of management
** metaphors, governance processes, and leadership techniques that is
** owned by Steven D. Stamps.  These copyrighted materials may be freely
** used, without alteration, by the community (users and developers)
** surrounding this GPL3-licensed software.  Additional copyright
** information is available at <http://www.flywheelms.org/copyrights>
**
**              GPL3 Software License
** This program is free software: you can use it, redistribute it and/or
** modify it under the terms of the GNU General Public License, version 3,
** as published by the Free Software Foundation. This program is distributed
** in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
** even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
** PURPOSE.  See the GNU General Public License for more details. You should
** have received a copy of the GNU General Public License, in a file named
** COPYING, along with this program.  If you cannot find your copy, see
** <http://www.gnu.org/licenses/gpl-3.0.html>.
*/

package com.flywheelms.library.fse.views;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.LinkedList;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.flywheelms.library.FmsLibraryActivity;
import com.flywheelms.library.FmsLibraryApplication;
import com.flywheelms.library.R;
import com.flywheelms.library.fdk.enumerator.FdkState;
import com.flywheelms.library.fmm.enumerator.FmmLockStatus;
import com.flywheelms.library.fse.enumerator.FseContentModificationState;
import com.flywheelms.library.fse.enumerator.FseLockModificationState;
import com.flywheelms.library.fse.enumerator.FseStyleModificationState;
import com.flywheelms.library.fse.model.FseDocumentSection;
import com.flywheelms.library.fse.model.FseDocumentSectionParagraphAudit;
import com.flywheelms.library.fse.model.FseDocumentSectionParagraphEditorContent;
import com.flywheelms.library.fse.model.FseParagraph;
import com.flywheelms.library.gcg.helper.GcgHelper;
import com.flywheelms.library.gcg.interfaces.GcgMultiShiftControllerParent;
import com.flywheelms.library.gcg.widget.GcgMultiShiftButton;
import com.flywheelms.library.gcg.widget.GcgMultiShiftClientButton;
import com.flywheelms.library.gcg.widget.GcgMultiShiftController;
import com.flywheelms.library.gcg.widget.GcgMultiShiftState;
import com.flywheelms.library.gcg.widget.GcgSpinnableMenu;

public abstract class FseDocumentSectionParagraphEditorContentViewLegacy extends FseDocumentSectionViewLegacy
		implements GcgMultiShiftControllerParent {

	private FseParagraphEditor paragraphEditor;
	protected LinearLayout documentSectionLayout;
	private ImageView paragraphStyleModificationImage;
	private ImageView paragraphContentModificationImage;
	private ImageView paragraphLockModificationImage;
	private FseStyleModificationState styleModificationState = FseStyleModificationState.UNCHANGED;
	private FseContentModificationState contentModificationState = FseContentModificationState.UNCHANGED;
	private FseLockModificationState lockModificationState = FseLockModificationState.UNCHANGED;
	// START - data members that are NULL in portrait mode
	private ArrayList<GcgMultiShiftButton> multiShiftButtonList;
	private GcgMultiShiftController multiShiftController;
	private ArrayList<GcgMultiShiftState> supportedMultiShiftStateList = new ArrayList<GcgMultiShiftState>(Arrays.asList(
			GcgMultiShiftState.OFF,
			GcgMultiShiftState.CTL,
			GcgMultiShiftState.SHIFT,
			GcgMultiShiftState.ALT ) );
	private RelativeLayout rightWindowPane;
	private FrameLayout rightFdkKeypadParent;
	private LinearLayout rightFdkKeypad;
	private Button fdkStartStopButton;
	private Button fdkNewlineButton;
	private Button fdkDeleteButton;
	private Button fdkLeftArrowButton;
	private Button fdkUpArrowButton;
	private Button fdkPeriodButton;
	private Button fdkCommaButton;
	private Button fdkSpaceButton;
	private Button fdkRightArrowButton;
	private Button fdkDownArrowButton;
	private boolean listeningForDictation = false;
	private char fdkCharacterBuffer = 'Z';
	private LinearLayout rightMenuLayout;
	private GcgSpinnableMenu rightSpinnableMenu;
	private GcgMultiShiftClientButton paragraphStyleIndentButton;
	private GcgMultiShiftClientButton paragraphStyleOutdentButton;
	private GcgMultiShiftClientButton paragraphStylePromoteButton;
	private GcgMultiShiftClientButton paragraphStyleDemoteButton;
	private GcgMultiShiftClientButton paragraphSequenceUpButton;
	private GcgMultiShiftClientButton paragraphSequenceDownButton;
	private GcgMultiShiftClientButton paragraphLockButton;
	private GcgMultiShiftClientButton paragraphUnlockButton;
	private RelativeLayout leftMenuFrame;
	// END - data members that are NULL in portrait mode
	boolean doNotChangeModificationState = true;

	public FseDocumentSectionParagraphEditorContentViewLegacy(Context context,
			AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void setDefaultFlywheelDictationKeyboardState() {
		this.defaultFdkState = FdkState.AVAILABLE;
		this.localFdkState = this.defaultFdkState;
	}
	
	@Override
	public void initialize(FseDocumentView aDocumentView) {
		super.initialize(aDocumentView);
		setDocumentSectionLayout();
		initGuiElements();
	}

	@Override
	public ViewGroup getDocumentSectionLayout() {
		return this.documentSectionLayout;
	}

	@Override
	public void setDocumentSectionLayout() {
		this.documentSectionLayout =
				(LinearLayout) this.documentView.findViewById(getDocumentSectionViewResourceId());
		sizeLayoutToDisplay();  // HACK ALERT - SDS
		/////////
		LinearLayout theLinearLayout = (LinearLayout) this.documentSectionLayout.findViewById(R.id.fse__scrollable_document);
		this.paragraphStyleModificationImage = (ImageView) theLinearLayout.findViewById(
				R.id.fse__document_body__heading__paragraph_style_status);
		this.paragraphContentModificationImage = (ImageView) theLinearLayout.findViewById(
				R.id.fse__document_body__heading__paragraph_content_status);
		this.paragraphLockModificationImage = (ImageView) theLinearLayout.findViewById(
				R.id.fse__document_body__heading__paragraph_lock_status);
	}

	private void sizeLayoutToDisplay() {
		FrameLayout theFrameLayout = (FrameLayout) this.documentSectionLayout.findViewById(R.id.fse__document__scrollview__frame);
		LinearLayout.LayoutParams theLayoutParams =
				(LinearLayout.LayoutParams) theFrameLayout.getLayoutParams();
		int theTabRowHeight = GcgHelper.getPixelsForDp(FmsLibraryApplication.getContext(), 100);
//		int theTargetSize = GcgHelper.getPixelsForDp(FmsLibraryApplication.getContext(), 394);
		int theOtherViewHeights = GcgHelper.getPixelsForDp(FmsLibraryApplication.getContext(), 59);
		int theLayoutHeight = GcgHelper.getScreenHeight() - (theTabRowHeight + theOtherViewHeights) + 3;
		theLayoutParams.height = theLayoutHeight;
		theFrameLayout.setLayoutParams(theLayoutParams);
	}

	public int getInitialParagraphFocusIndex() {
		return this.paragraphEditor.getUpdatedParagraphFocusIndex();
	}

	public int getInitialParagraphFocusCursorPosition() {
		return this.paragraphEditor.getUpdatedParagraphFocusCursorPosition();
	}

	public LinkedList<FseParagraphView> getParagraphViewList() {
		return this.paragraphEditor.getParagraphViewList();
	}

	private void initGuiElements() {
		if(GcgHelper.isLandscapeMode()) {
			initParagraphEditorView();
			initLeftMenu();
			initRightMenu();
			initFdk();
			initMultiShiftWidget();
			configMultiShiftClientButtons();
			configMultiShiftStateListeners();
			initTabControlButtons();
		} else {
			initParagraphEditorView();
			configMultiShiftStateListeners();
			initTabControlButtons();
		}
	}

	private void initFdk() {
		this.fdkStartStopButton = (Button) fdkGetLeftKeypad().findViewById(R.id.fdk_start_button);
		this.fdkStartStopButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStartDictation();
		    } 
		});
		this.fdkNewlineButton = (Button) fdkGetLeftKeypad().findViewById(R.id.fdk_newline_button);
		this.fdkNewlineButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchNewline();
		    } 
		});
		this.fdkDeleteButton = (Button) fdkGetLeftKeypad().findViewById(R.id.fdk_delete_button);
		this.fdkDeleteButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchBackspace();
		    } 
		});
		this.fdkDeleteButton.setOnLongClickListener(new OnLongClickListener() { 
	        @Override
	        public boolean onLongClick(View v) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchDelete();
	            return true;
	        }
	    });
		this.fdkLeftArrowButton = (Button) fdkGetLeftKeypad().findViewById(R.id.fdk_cursor_left_button);
		this.fdkLeftArrowButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchLeftArrow();
		    } 
		});
		this.fdkLeftArrowButton.setOnLongClickListener(new OnLongClickListener() { 
	        @Override
	        public boolean onLongClick(View v) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = '/';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return true;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchForwardSlash();
		        return true;
		    }
	    });
		this.fdkUpArrowButton = (Button) fdkGetLeftKeypad().findViewById(R.id.fdk_cursor_up_button);
		this.fdkUpArrowButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchUpArrow();
		    } 
		});
		
		this.rightFdkKeypadParent = (FrameLayout) this.rightWindowPane.findViewById(R.id.fdk__right_keypad_parent);
		this.rightFdkKeypad = (LinearLayout) this.rightFdkKeypadParent.findViewById(R.id.fdk__right_keypad);

		this.fdkPeriodButton = (Button) fdkGetRightKeypad().findViewById(R.id.fdk_period_button);
		this.fdkPeriodButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = '.';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchPeriod();
		    }
		});
		this.fdkPeriodButton.setOnLongClickListener(new OnLongClickListener() { 
	        @Override
	        public boolean onLongClick(View v) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = '?';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return true;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchQuestionMark();
		        return true;
		    }
	    });
		this.fdkSpaceButton = (Button) fdkGetRightKeypad().findViewById(R.id.fdk_space_button);
		this.fdkSpaceButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = ' ';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchSpace();
		    }
		});
		this.fdkSpaceButton.setOnLongClickListener(new OnLongClickListener() { 
	        @Override
	        public boolean onLongClick(View v) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = '!';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return true;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchExclamation();
		        return true;
		    }
	    });
		this.fdkCommaButton = (Button) fdkGetRightKeypad().findViewById(R.id.fdk_comma_button);
		this.fdkCommaButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = ',';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchComma();
		    }
		});
		this.fdkCommaButton.setOnLongClickListener(new OnLongClickListener() { 
	        @Override
	        public boolean onLongClick(View v) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = ';';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return true;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchSemicolon();
		        return true;
		    }
	    });
		this.fdkRightArrowButton = (Button) fdkGetRightKeypad().findViewById(R.id.fdk_cursor_right_button);
		this.fdkRightArrowButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchRightArrow();
		    } 
		});
		this.fdkRightArrowButton.setOnLongClickListener(new OnLongClickListener() { 
	        @Override
	        public boolean onLongClick(View v) {
				if(FseDocumentSectionParagraphEditorContentViewLegacy.this.listeningForDictation) {
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkCharacterBuffer = '-';
					FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkStopDictation();
					return true;
				}
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchDash();
		        return true;
		    }
	    });
		this.fdkDownArrowButton = (Button) fdkGetRightKeypad().findViewById(R.id.fdk_cursor_down_button);
		this.fdkDownArrowButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View aView) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchDownArrow();
		    } 
		});
	}

	protected void fdkDispatchDash() {
		this.paragraphEditor.fdkDispatchDash();
	}

	protected void fdkDispatchExclamation() {
		this.paragraphEditor.fdkDispatchExclamation();
	}

	protected void fdkDispatchQuestionMark() {
		this.paragraphEditor.fdkDispatchQuestionMark();
	}

	protected void fdkDispatchDownArrow() {
		this.paragraphEditor.fdkDispatchDownArrow();
	}

	protected void fdkDispatchRightArrow() {
		this.paragraphEditor.fdkDispatchRightArrow();
	}

	protected void fdkDispatchSpace() {
		this.paragraphEditor.fdkDispatchSpace();
	}

	protected void fdkDispatchForwardSlash() {
		this.paragraphEditor.fdkDispatchForwardSlash();
	}

	protected void fdkDispatchComma() {
		this.paragraphEditor.fdkDispatchComma();
	}

	protected void fdkDispatchSemicolon() {
		this.paragraphEditor.fdkDispatchSemicolon();
	}

	protected void fdkDispatchPeriod() {
		this.paragraphEditor.fdkDispatchPeriod();
	}

	protected void fdkDispatchUpArrow() {
		this.paragraphEditor.fdkDispatchUpArrow();
	}

	protected void fdkDispatchLeftArrow() {
		this.paragraphEditor.fdkDispatchLeftArrow();
	}

	protected void fdkDispatchDelete() {
		this.paragraphEditor.fdkDispatchDelete();
	}

	protected void fdkDispatchBackspace() {
		if(this.listeningForDictation) {
			fdkCancelDictation();
		} else {
			this.paragraphEditor.fdkDispatchBackspace();
		}
	}

	protected void fdkDispatchNewline() {
		this.paragraphEditor.fdkDispatchNewline();
	}

	@Override
	void viewDocumentSection(FseDocumentSection aDocumentSection) {
		this.paragraphEditor.viewDocumentSection((FseDocumentSectionParagraphEditorContent)aDocumentSection);
	}

	@Override
	public String sectionIsModified() {
		return null;
	}

	private void initParagraphEditorView() {
		this.paragraphEditor = (FseParagraphEditor) this.documentSectionLayout.findViewById(R.id.fse__paragraph_editor);
		this.paragraphEditor.initialize(this);
	}

	private void initLeftMenu() {
		this.leftMenuFrame = (RelativeLayout) this.documentSectionLayout.findViewById(R.id.left_menu_frame);
	}
	
	@Override
	public void activateDocumentSectionTab() {
		super.activateDocumentSectionTab();
		FrameLayout theParentFrameLayout = (FrameLayout) this.documentSectionLayout.getParent();
		theParentFrameLayout.bringChildToFront(this.documentSectionLayout);
		theParentFrameLayout.invalidate();
		this.paragraphEditor.resetFocus();
		if(GcgHelper.isLandscapeMode()) {
			RelativeLayout theViewParent = (RelativeLayout) getDocumentView().getFseFragment().getLeftMenuInclude().getParent(); 
			if(theViewParent != null) {
				theViewParent.removeView(getDocumentView().getFseFragment().getLeftMenuInclude());
			}
			this.leftMenuFrame.addView(getDocumentView().getFseFragment().getLeftMenuInclude(), 0);
		}
	}
	
	protected GcgSpinnableMenu getLeftSpinnableMenu() {
		return getFseFragment().getLeftSpinnableMenu();
	}
	
	public int getOriginalInitialParagraphFocusIndex() {
		return this.paragraphEditor.getOriginalInitialParagraphFocusIndex();
	}

	public int getOriginalInitialParagraphFocusCursorPosition() {
		return this.paragraphEditor.getOriginalInitialParagraphFocusCursorPosition();
	}
	
	/////////////////////////////////////////////////////////////////////////////////

	protected void initRightMenu() {
		int[] theMenuBodyResourceIdArray = {
				R.id.fse__style_menu__body,
				R.id.fse__sequence_menu__body,
				R.id.fse__list_menu__body,
				R.id.fse__insert_menu__body,
				R.id.fse__lock_menu__body };
		this.rightWindowPane =
				(RelativeLayout) this.documentView.getDocumentViewLayout().findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.fse__right_window_pane);
		this.rightMenuLayout = (LinearLayout) this.rightWindowPane.findViewById(R.id.fse__right_menu_layout);
		this.rightSpinnableMenu = new GcgSpinnableMenu(
				getContext(),
				this.rightMenuLayout,
				GcgSpinnableMenu.DECORATORS_RIGHT,
				R.id.fse__right_menu__heading_spinner,
				R.array.fse__right_menu__heading_array,
				theMenuBodyResourceIdArray );
		initStyleMenu();
		initSequenceMenu();
		initListsMenu();
		initLockMenu();
	}

	private void initMultiShiftWidget() {
		GcgMultiShiftButton theLeftTouchShiftButton = ((GcgMultiShiftButton)
				((LinearLayout) this.leftMenuFrame.findViewById(R.id.fse__left_menu__shift_button_frame)).
				findViewById(R.id.fse__left_menu__shift_button) );
		theLeftTouchShiftButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View v) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.multiShiftController.onLeftButtonClick();
		    } 
		});
		GcgMultiShiftButton theRightTouchShiftButton =
				(GcgMultiShiftButton) this.rightWindowPane.findViewById(R.id.fse__right_menu__shift_button);
//				((LinearLayout) this.rightSpinnableMenu.getMenuFrameLayout().findViewById(R.id.fse__right_menu__shift_button__frame)).
//				findViewById(R.id.fse__right_menu__shift_button) );
		theRightTouchShiftButton.setOnClickListener(new OnClickListener() {
			
			@Override
		    public void onClick(View v) {
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.multiShiftController.onRightButtonClick();
		    } 
		});
		this.multiShiftButtonList = new ArrayList<GcgMultiShiftButton>();
		this.multiShiftButtonList.add(theLeftTouchShiftButton);
		this.multiShiftButtonList.add(theRightTouchShiftButton);
		this.multiShiftController = new GcgMultiShiftController(this);
	}

	private void configMultiShiftClientButtons() {
		this.multiShiftController.addButtonListener(this.paragraphStyleIndentButton);
		this.paragraphStyleIndentButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphStyleIndent();
			}
		} );
		this.multiShiftController.addButtonListener(this.paragraphStyleOutdentButton);
		this.paragraphStyleOutdentButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphStyleOutdent();
			}
		} );
		this.multiShiftController.addButtonListener(this.paragraphStylePromoteButton);
		this.paragraphStylePromoteButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphStylePromote();
			}
		} );
		this.multiShiftController.addButtonListener(this.paragraphStyleDemoteButton);
		this.paragraphStyleDemoteButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphStyleDemote();
			}
		} );
		this.multiShiftController.addButtonListener(this.paragraphSequenceUpButton);
		this.paragraphSequenceUpButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphSequenceUp();
			}
		} );
		this.multiShiftController.addButtonListener(this.paragraphSequenceDownButton);
		this.paragraphSequenceDownButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphSequenceDown();
			}
		} );
		this.multiShiftController.addButtonListener(this.paragraphLockButton);
		this.paragraphLockButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphLock();
			}
		} );
		this.multiShiftController.addButtonListener(this.paragraphUnlockButton);
		this.paragraphUnlockButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				FseDocumentSectionParagraphEditorContentViewLegacy.this.onClickParagraphUnlock();
			}
		} );
	}
	
	private void configMultiShiftStateListeners() {
		if(this.multiShiftController != null) {
			this.multiShiftController.addMultiShiftStateListener(this.paragraphEditor);
		}
	}

	private void initStyleMenu() {
		this.paragraphStyleIndentButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.style_indent_button);
		this.paragraphStyleOutdentButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.style_outdent_button);
		this.paragraphStylePromoteButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.style_promote_button);
		this.paragraphStyleDemoteButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.style_demote_button);
	}

	private void initSequenceMenu() {
		this.paragraphSequenceUpButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.sequence_up_button);
		this.paragraphSequenceDownButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.sequence_down_button);
	}
	
	private void initListsMenu() {
		// TODO Auto-generated method stub
	}

	private void initLockMenu() {
		this.paragraphLockButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.lock__lock__button);
		this.paragraphUnlockButton = (GcgMultiShiftClientButton) this.documentView.getDocumentViewLayout()
				.findViewById(getDocumentSectionViewResourceId()).findViewById(R.id.lock__unlock__button);
	}
	
	/////  button callbacks  //////
	
	public void onClickParagraphStyleIndent() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphStyleIndentButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
		}
		if(theParagraphViewList != null && this.paragraphEditor.canIndentList(theParagraphViewList)) {
			this.paragraphEditor.styleIndentParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				this.paragraphEditor.resetParagraphViewSelectionList(theParagraphViewList);
				this.paragraphEditor.setParagraphSpinnerFocusLost();
				this.paragraphEditor.setParagraphSpinnerFocus(theParagraphViewList);
			}
		}
		this.multiShiftController.resetState();
	}
	
	public void onClickParagraphStyleOutdent() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphStyleOutdentButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
		}
		if(theParagraphViewList != null && this.paragraphEditor.canOutdentList(theParagraphViewList)) {
			this.paragraphEditor.styleOutdentParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				this.paragraphEditor.resetParagraphViewSelectionList(theParagraphViewList);
				this.paragraphEditor.setParagraphSpinnerFocusLost();
				this.paragraphEditor.setParagraphSpinnerFocus(theParagraphViewList);
			}
		}
		this.multiShiftController.resetState();
	}

	protected void onClickParagraphStylePromote() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphStylePromoteButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
		}
		if(theParagraphViewList != null && this.paragraphEditor.canPromoteList(theParagraphViewList)) {
			this.paragraphEditor.stylePromoteParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				this.paragraphEditor.resetParagraphViewSelectionList(theParagraphViewList);
				this.paragraphEditor.setParagraphSpinnerFocusLost();
				this.paragraphEditor.setParagraphSpinnerFocus(theParagraphViewList);
			}
		}
		this.multiShiftController.resetState();
	}
	
	protected void onClickParagraphStyleDemote() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphStyleDemoteButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
		}
		if(theParagraphViewList != null && this.paragraphEditor.canDemoteList(theParagraphViewList)) {
			this.paragraphEditor.styleDemoteParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				this.paragraphEditor.resetParagraphViewSelectionList(theParagraphViewList);
				this.paragraphEditor.setParagraphSpinnerFocusLost();
				this.paragraphEditor.setParagraphSpinnerFocus(theParagraphViewList);
			}
		}
		this.multiShiftController.resetState();
	}
	
	public void onClickParagraphLock() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphStyleIndentButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
		}
		if(theParagraphViewList != null) {
			this.paragraphEditor.lockParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				updateLockModificationState();
			}
		}
		this.multiShiftController.resetState();
	}
	
	public void onClickParagraphUnlock() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphStyleIndentButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = this.paragraphEditor.getParagraphViewSelectionList();
		}
		if(theParagraphViewList != null) {
			this.paragraphEditor.unlockParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				updateLockModificationState();
			}
		}
		this.multiShiftController.resetState();
	}

	@SuppressWarnings("unchecked")
	protected void onClickParagraphSequenceUp() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphSequenceUpButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = (LinkedList<FseParagraphView>) this.paragraphEditor.getParagraphViewSelectionList().clone();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = (LinkedList<FseParagraphView>) this.paragraphEditor.getParagraphViewSelectionList().clone();
		}
		if(theParagraphViewList != null && this.paragraphEditor.canSequenceListUp(theParagraphViewList)) {
			this.paragraphEditor.sequenceUpParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				this.paragraphEditor.resetParagraphViewSelectionList(theParagraphViewList);
				this.paragraphEditor.setParagraphSpinnerFocusLost();
				this.paragraphEditor.setParagraphSpinnerFocus(theParagraphViewList);
			}
		}
		this.multiShiftController.resetState();
	}

	@SuppressWarnings("unchecked")
	protected void onClickParagraphSequenceDown() {
		LinkedList<FseParagraphView> theParagraphViewList = null;
		switch(this.paragraphSequenceDownButton.getMultiShiftState()) {
		case OFF:
			theParagraphViewList = (LinkedList<FseParagraphView>) this.paragraphEditor.getParagraphViewSelectionList().clone();
			break;
		case CTL:
			break;
		case SHIFT:
			break;
		case ALT:
			theParagraphViewList = this.paragraphEditor.getParagraphViewDescendentList(this.paragraphEditor.getParagraphViewFocus());
			theParagraphViewList.add(0, this.paragraphEditor.getParagraphViewFocus());
			break;
		case ALT_SHIFT:
			break;
		default:
			theParagraphViewList = (LinkedList<FseParagraphView>) this.paragraphEditor.getParagraphViewSelectionList().clone();
		}
		if(theParagraphViewList != null && this.paragraphEditor.canSequenceListDown(theParagraphViewList)) {
			this.paragraphEditor.sequenceDownParagraphViewList(theParagraphViewList);
			if(theParagraphViewList.size() > 0) {
				this.paragraphEditor.resetParagraphViewSelectionList(theParagraphViewList);
				this.paragraphEditor.setParagraphSpinnerFocusLost();
				this.paragraphEditor.setParagraphSpinnerFocus(theParagraphViewList);
			}
		}
		this.multiShiftController.resetState();
	}
	
	///////  END Button Callbacks  ///////////
	
	public GcgMultiShiftController getMultiShiftController() {
		return this.multiShiftController;
	}

	public void resetMultiShiftControllerState() {
		if(this.multiShiftController != null) {
			if(this.multiShiftController.getMultiShiftState() != GcgMultiShiftState.OFF) {
				this.multiShiftController.resetState();
				this.paragraphEditor.resetParagraphSpinnerSelectionMode();
			}
		}
	}

	public boolean isMultiShiftControllerParagraphSelectionMode() {
		if(this.multiShiftController != null) {
			return this.multiShiftController.isItemSelectionState();
		}
		return false;
	}

	@Override
	public boolean isMultipleSelections() {
		return this.paragraphEditor.isMultipleSelections();
	}

	@Override
	public ArrayList<GcgMultiShiftState> getSupportedMultiShiftStateList() {
		return this.supportedMultiShiftStateList;
	}

	@Override
	public ArrayList<GcgMultiShiftButton> getShiftButtonList() {
		return this.multiShiftButtonList;
	}
	
	////////////////
	
	protected static void copyToDocumentSectionParagraphEditorContent(
			FseDocumentSectionParagraphEditorContentViewLegacy aDocumentSectionParagraphEditorContentView,
			FseDocumentSectionParagraphEditorContent aDocumentSectionParagraphEditorContent) {
		// TODO - cloning
		aDocumentSectionParagraphEditorContent.setInitialParagraphFocusIndex(aDocumentSectionParagraphEditorContentView.getInitialParagraphFocusIndex());
		aDocumentSectionParagraphEditorContent.setInitialParagraphFocusCursorPosition(aDocumentSectionParagraphEditorContentView.getInitialParagraphFocusCursorPosition());
		aDocumentSectionParagraphEditorContent.setLockModificationState(aDocumentSectionParagraphEditorContentView.getLockModificationState());
		aDocumentSectionParagraphEditorContent.setContentModificationState(aDocumentSectionParagraphEditorContentView.getContentModificationState());
		aDocumentSectionParagraphEditorContent.setStyleModificationState(aDocumentSectionParagraphEditorContentView.getStyleModificationState());
		for(FseParagraphView theParagraphView : aDocumentSectionParagraphEditorContentView.getParagraphViewList()) {
			aDocumentSectionParagraphEditorContent.getParagraphList().add(theParagraphView.generateFseParagraph());
		}
	}
	
	public FseContentModificationState getContentModificationState() {
		return this.contentModificationState;
	}

	public boolean isContentModified() {
		return this.contentModificationState == FseContentModificationState.NEW || this.contentModificationState == FseContentModificationState.MODIFIED;
	}
	
	public FseLockModificationState getLockModificationState() {
		return this.lockModificationState;
	}

	public boolean isLockStateModified() {
		return this.lockModificationState == FseLockModificationState.MODIFIED;
	}
	
	public FseStyleModificationState getStyleModificationState() {
		return this.styleModificationState;
	}

	public boolean isStyleModified() {
		return this.contentModificationState == FseContentModificationState.NEW || this.contentModificationState == FseContentModificationState.MODIFIED;
	}
	
	public void setAsNewBaseline() {
		this.styleModificationState = FseStyleModificationState.UNCHANGED;
		this.paragraphStyleModificationImage.setImageDrawable(FseContentModificationState.UNCHANGED.getDrawable());
		this.contentModificationState = FseContentModificationState.UNCHANGED;
		this.paragraphContentModificationImage.setImageDrawable(FseContentModificationState.UNCHANGED.getDrawable());
		this.lockModificationState = FseLockModificationState.UNCHANGED;
		this.paragraphLockModificationImage.setImageDrawable(FseLockModificationState.UNCHANGED.getDrawable());
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			theParagraphView.setAsNewBaseline();
		}
	}
	
	public void resetModificationState() {
		this.styleModificationState = FseStyleModificationState.UNCHANGED;
		this.paragraphStyleModificationImage.setImageDrawable(FseStyleModificationState.UNCHANGED.getDrawable());
		this.contentModificationState = FseContentModificationState.UNCHANGED;
		this.paragraphContentModificationImage.setImageDrawable(FseContentModificationState.UNCHANGED.getDrawable());
		this.lockModificationState = FseLockModificationState.UNCHANGED;
		this.paragraphLockModificationImage.setImageDrawable(FseLockModificationState.UNCHANGED.getDrawable());
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			theParagraphView.resetModificationState();
		}
	}
	
	public void enableModificationStateUpdates() {
		this.doNotChangeModificationState = false;
	}
	
	public void disableModificationStateUpdates() {
		this.doNotChangeModificationState = true;
	}

	public boolean modificationStateDisabled() {
		return this.doNotChangeModificationState;
	}

	public FseDocumentSectionParagraphAudit getParagraphAudit() {
		FseDocumentSectionParagraphAudit theParagraphAudit = new FseDocumentSectionParagraphAudit(this.getSectionType());
		theParagraphAudit.setParagraphsNewCount(getParagraphsNewCount());
		theParagraphAudit.setParagraphsModifiedCount(getParagraphsContentModifiedCount());
		theParagraphAudit.setParagraphsUnchangedCount(getParagraphsUnchangedCount());
		theParagraphAudit.setParagraphsLockedCount(getParagraphsLockedCount());
		theParagraphAudit.setParagraphsUnlockedCount(getParagraphsUnlockedCount());
		theParagraphAudit.setParagraphsDeletedCount(getParagraphsDeletedCount());
		return theParagraphAudit;
	}

	private Hashtable<String, FseParagraphView> getParagraphViewHashtable() {
		Hashtable<String, FseParagraphView> theParagraphViewHashtable = new Hashtable<String, FseParagraphView>();
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			theParagraphViewHashtable.put(theParagraphView.getParagraphId(), theParagraphView);
		}
		return theParagraphViewHashtable;
	}

	private static Hashtable<String, FseParagraph> getBaselineDocumentParagraphHashtable(LinkedList<FseParagraph> aBaselineDocumentParagraphList) {
		Hashtable<String, FseParagraph> theParagraphHashtable = new Hashtable<String, FseParagraph>();
		for(FseParagraph theParagraph : aBaselineDocumentParagraphList) {
			theParagraphHashtable.put(theParagraph.getParagraphId(), theParagraph);
		}
		return theParagraphHashtable;
	}

	private int getParagraphsUnchangedCount() {
		int theCount = 0;
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.getContentModificationState() == FseContentModificationState.UNCHANGED) {
				++ theCount;
			}
		}
		return theCount;
	}

	private int getParagraphsNewCount() {
		int theCount = 0;
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.getContentModificationState() == FseContentModificationState.NEW) {
				++ theCount;
			}
		}
		return theCount;
	}

	private int getParagraphsContentModifiedCount() {
		int theCount = 0;
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.getContentModificationState() == FseContentModificationState.MODIFIED) {
				++ theCount;
			}
		}
		return theCount;
	}

	public int getParagraphsLockedCount() {
		LinkedList<FseParagraph> aBaselineDocumentParagraphList =
				getDocumentView().getBaselineDocument().getParagraphList(getSectionType());
		Hashtable<String, FseParagraph> theBaselineParagraphHashTable =
				FseDocumentSectionParagraphEditorContentViewLegacy.getBaselineDocumentParagraphHashtable(aBaselineDocumentParagraphList);
		int theCount = 0;
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.getLockStatus() == FmmLockStatus.LOCKED) {
				FseParagraph theBaselineParagraph = theBaselineParagraphHashTable.get(theParagraphView.getParagraphId());
				if(theBaselineParagraph == null || theBaselineParagraph.getLockStatus() != FmmLockStatus.LOCKED) {
					++theCount;
				}
			}
		}
		return theCount;
	}

	public int getParagraphsUnlockedCount() {
		LinkedList<FseParagraph> aBaselineDocumentParagraphList =
				getDocumentView().getBaselineDocument().getParagraphList(getSectionType());
		Hashtable<String, FseParagraph> theBaselineParagraphHashTable = getBaselineDocumentParagraphHashtable(aBaselineDocumentParagraphList);
		int theCount = 0;
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.getLockModificationState() == FseLockModificationState.MODIFIED &&
					! theParagraphView.getAuditBlock().isLocked()) {
				FseParagraph theBaselineParagraph = theBaselineParagraphHashTable.get(theParagraphView.getParagraphId());
				if(theBaselineParagraph == null || theBaselineParagraph.isLocked() ) {
					++theCount;
				}
			}
		}
		return theCount;
	}

	public int getParagraphsDeletedCount() {
		LinkedList<FseParagraph> aBaselineDocumentParagraphList =
				getDocumentView().getBaselineDocument().getParagraphList(getSectionType());
		Hashtable<String, FseParagraphView> theParagraphViewHashtable = getParagraphViewHashtable();
		int theCount = 0;
		for(FseParagraph theParagraph : aBaselineDocumentParagraphList) {
			if(! theParagraphViewHashtable.containsKey(theParagraph.getParagraphId())) {
				++theCount;
			}
		}
		return theCount;
	}
	
	////

	public void updateLockModificationState() {
		setLockModificationState(determineParagraphLockModificationState());
	}

	public void updateLockModificationState(FseLockModificationState aModificationState) {
		if(this.lockModificationState == aModificationState) {
			return;
		}
		setLockModificationState(determineParagraphLockModificationState());
	}

	public void setLockModificationState(FseLockModificationState aModificationState) {
		if(this.lockModificationState == aModificationState) {
			return;
		}
		this.lockModificationState = aModificationState;
		this.paragraphLockModificationImage.setImageDrawable(aModificationState.getDrawable());
	}

	public FseLockModificationState determineParagraphLockModificationState() {
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.isLockModified()) {
				return FseLockModificationState.MODIFIED;
			}
		}
		return FseLockModificationState.UNCHANGED;
	}
	
	////

	public void updateContentModificationState() {
		setContentModificationState(determineParagraphContentModificationState());
	}
	
	public void updateContentModificationState(FseContentModificationState aModificationState) {
		if(this.contentModificationState == aModificationState) {
			return;
		}
		setContentModificationState(determineParagraphContentModificationState());
	}
	
	public void setContentModificationState(FseContentModificationState aModificationState) {
		if(this.contentModificationState == aModificationState) {
			return;
		}
		if(this.contentModificationState == FseContentModificationState.NEW && aModificationState == FseContentModificationState.MODIFIED) {
			return;
		}
		this.contentModificationState = aModificationState;
		this.paragraphContentModificationImage.setImageDrawable(aModificationState.getDrawable());
	}

	public FseContentModificationState determineParagraphContentModificationState() {
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.isNew() || theParagraphView.isContentModified()) {
				return FseContentModificationState.MODIFIED;
			}
		}
		return FseContentModificationState.UNCHANGED;
	}
	
	////

	public void updateStyleModificationState() {
		setStyleModificationState(determineParagraphStyleModificationState());
	}
	
	public void updateStyleModificationState(FseStyleModificationState aModificationState) {
		if(this.styleModificationState == aModificationState) {
			return;
		}
		setStyleModificationState(determineParagraphStyleModificationState());
//		this.styleModificationState = aModificationState;
//		if(aModificationState == FseModificationState.UNCHANGED) {
//			this.bodyHeadingTextView.setText(BODY_HEADING__DOCUMENT_UNMODIFIED);
//		} else {
//			this.bodyHeadingTextView.setText(BODY_HEADING__DOCUMENT_MODIFIED);
//		}
	}
	
	public void setStyleModificationState(FseStyleModificationState aModificationState) {
		if(this.styleModificationState == aModificationState) {
			return;
		}
		this.styleModificationState = aModificationState;
		this.paragraphStyleModificationImage.setImageDrawable(aModificationState.getDrawable());
	}

	public FseStyleModificationState determineParagraphStyleModificationState() {
		for(FseParagraphView theParagraphView : this.paragraphEditor.getParagraphViewList()) {
			if(theParagraphView.isStyleModified()) {
				return FseStyleModificationState.MODIFIED;
			}
		}
		return FseStyleModificationState.UNCHANGED;
	}
	
	////

	public FseContentModificationState getModificationState() {
		if(this.lockModificationState == FseLockModificationState.UNCHANGED &&
				this.contentModificationState == FseContentModificationState.UNCHANGED &&	
				this.styleModificationState == FseStyleModificationState.UNCHANGED ) {
			return FseContentModificationState.UNCHANGED;
		}
		return FseContentModificationState.MODIFIED;
	}
	
	@Override
	protected LinearLayout fdkGetRightKeypad() {
		return this.rightFdkKeypad;
	}
	
	@Override
	protected LinearLayout fdkGetLeftKeypad() {
		return getFseFragment().getLeftFdkKeypad();
	}
	
	@Override
	public void fdkActivateKeypads(boolean aBoolean) {
		if(GcgHelper.isLandscapeMode()) {
			this.areFdkKeypadsActive = aBoolean;
			int theKeypadVisibility = aBoolean ? View.VISIBLE : View.INVISIBLE;
			int theMenuVisibility = aBoolean ? View.INVISIBLE : View.VISIBLE;
			fdkGetRightKeypad().setVisibility(theKeypadVisibility);
			this.rightMenuLayout.setVisibility(theMenuVisibility);
			fdkGetLeftKeypad().setVisibility(theKeypadVisibility);
			this.documentView.getFseFragment().getLeftMenuLayout().setVisibility(theMenuVisibility);
		}
	}
	
	@Override
	public void fdkStartDictation() {
		if(this.listeningForDictation) {
			((FmsLibraryActivity) getFseFragment().getActivity()).stopDictation();
			this.fdkStartStopButton.setBackgroundResource(R.drawable.fdk_key__start);
			this.listeningForDictation = false;
		} else {
			((FmsLibraryActivity) getFseFragment().getActivity()).startDictation();
			this.fdkStartStopButton.setBackgroundResource(R.drawable.fdk_key__stop);
			this.listeningForDictation = true;
		}
	}
	
	@Override
	public void fdkStopDictation() {
		if(this.listeningForDictation) {
			((FmsLibraryActivity) getFseFragment().getActivity()).stopDictation();
			this.fdkStartStopButton.setBackgroundResource(R.drawable.fdk_key__start);
			this.listeningForDictation = false;
		}
	}
	
	@Override
	public void fdkDictationResults(ArrayList<String> theWordList) {
		fdkStopDictation();
		this.paragraphEditor.fdkDictationResults(theWordList.get(0));
//		GcgHelper.makeToast(theWordList.get(0));
		switch(this.fdkCharacterBuffer) {
			case '.':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchPeriod();
		        this.fdkCharacterBuffer = 'Z';
		        break;
			case '?':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchQuestionMark();
		        this.fdkCharacterBuffer = 'Z';
		        break;
			case ' ':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchSpace();
		        this.fdkCharacterBuffer = 'Z';
		        break;
			case '!':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchExclamation();
		        this.fdkCharacterBuffer = 'Z';
		        break;
			case ',':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchComma();
		        this.fdkCharacterBuffer = 'Z';
		        break;
			case ';':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchSemicolon();
		        this.fdkCharacterBuffer = 'Z';
		        break;
			case '-':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchDash();
		        this.fdkCharacterBuffer = 'Z';
		        break;
			case '/':
		        FseDocumentSectionParagraphEditorContentViewLegacy.this.fdkDispatchForwardSlash();
		        this.fdkCharacterBuffer = 'Z';
		        break;
	        default:
		}
		return;
	}
	
	@Override
	public void fdkCancelDictation() {
		if(this.listeningForDictation) {
			this.fdkStartStopButton.setBackgroundResource(R.drawable.fdk_key__start);
			this.listeningForDictation = false;
			((FmsLibraryActivity) getFseFragment().getActivity()).cancelDictation();
		}
	}
	
}